package start;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.ServerNotActiveException;

import javax.swing.JOptionPane;

import application.exceptions.DatabaseException;
import application.exceptions.UserNotInDbException;
import application.exceptions.WrongCredentialsException;
import application.server.Server;

public class LoginTest {
	public static void main(String[] args){
		try {
			Server serviceStub = (Server) Naming.lookup("rmi://" + args[0] + ":" + args[1]
					+ "/LibMan");
				String s="";
				try {
					s = serviceStub.login("sma8492", "prytveng");
				} catch (UserNotInDbException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
				System.out.println(s);
			    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			    try {
					in.readLine();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		}	catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			JOptionPane.showMessageDialog(null, "Server - Verbindungsfehler",
					"Error", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		} catch (ServerNotActiveException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WrongCredentialsException e) {
			System.out.println(e.toString());
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DatabaseException e){
			
		}
	}
}
